import request from '@/service'

export const getUserList = data => {
  return request({
    method: 'get',
    url: 'roles'
  })
}
// 删除角色指定权限
export const delUserPermiss = (roleID, rightID) => {
  return request({
    method: 'delete',
    url: `roles/${roleID.id}/rights/${rightID}`
  })
}

// 所有权限列表 :tree
export const getAllPermiss = params => {
  return request({
    method: 'get',
    url: 'rights/tree'
  })
}

// 角色授权
export const getUserPermiss = (roleId, data) => {
  return request({
    method: 'post',
    url: `roles/${roleId}/rights`,
    data: {
      rids: data
    }
  })
}

// 添加角色
export const addRights = data => {
  return request({
    method: 'post',
    url: 'roles',
    data
  })
}

// 根据 ID 查询角色
export const idRights = id => {
  return request({
    method: 'get',
    url: `roles/${id}`
  })
}

// 编辑角色 注意这里参数是roleId
export const editRights = ({ roleId, roleName, roleDesc }) => {
  return request({
    method: 'put',
    url: `roles/${roleId}`,
    data: {
      roleName,
      roleDesc
    }
  })
}

// 删除角色
export const delRights = id => {
  return request({
    method: 'delete',
    url: `roles/${id}`
  })
}
